from fastapi import FastAPI
from starlette.staticfiles import StaticFiles
from app.api import router as api_router
from app.core.config import settings

app = FastAPI(
    title=settings.app_name,
    version=settings.app_version,
    description="商城系统API - 包含商品、用户、购物车、订单模块"
)

# 注册static目录
app.mount("/static", StaticFiles(directory="static"), name="static")

# API路由
app.include_router(api_router, prefix="/api")


@app.get("/")
async def root():
    return {
        "message": "欢迎使用mall-iamyuan商城系统",
        "version": settings.app_version,
        "modules": {
            "product": "/api/v1/product",
            "users": "/api/v1/users",
            "cart": "/api/v1/cart",
            "orders": "/api/v1/orders"
        }
    }


@app.get("/health")
async def health_check():
    return {"status": "healthy"}


if __name__ == "__main__":
    import uvicorn
    uvicorn.run(
        "main:app",
        host="127.0.0.1",
        port=9420,
        reload=settings.debug
    )
